<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *公告管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'请假记录'),	
);
if($_RQ['op']=='list'){
	$params=array('storeid'=>$this->store_id);
	$params['uniacid']=$_SESSION['uniacid'];
	if(!empty($_RQ['title'])){
		$params['title like']='%'.trim($_RQ['title']).'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['id'])){
		$params['bodyid']=intval($_RQ['id']);
		$return['params']['id']=intval($_RQ['id']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_edu_body_out',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$item['mid']=pdo_getcolumn('jy_edu_body',array('id'=>$item['bodyid']),'mid');
			$item['member']=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
			$item['nickname']=$item['member']['nickname'];
			$item['name']=pdo_getcolumn('jy_edu_body',array('id'=>$item['bodyid']),'name');
			$item['sex']=pdo_getcolumn('jy_edu_body',array('id'=>$item['bodyid']),'sex');
			$item['sex']=$item['sex']==0?'女':'男';
			if($item['classid']){
				$item['classtitle']=pdo_getcolumn('jy_edu_class',array('id'=>$item['classid']),'title');
				$item['classworkerid']=pdo_getcolumn('jy_edu_class',array('id'=>$item['classid']),'workerid');
				$item['classgroup']=pdo_getcolumn('jy_edu_class_group',array('id'=>$item['classid']),'title');
				$item['classworker']=pdo_getcolumn('jy_edu_worker',array('id'=>$item['classworkerid']),'name');
			}
			if($item['lesson_id']){
				$item['lessontitle']=pdo_getcolumn('jy_edu_lesson',array('id'=>$item['lesson_id']),'title');
				$item['lessonworkerid']=pdo_getcolumn('jy_edu_lesson',array('id'=>$item['lesson_id']),'workerid');
				$item['lessonworker']=pdo_getcolumn('jy_edu_worker',array('id'=>$item['lessonworkerid']),'name');
				$item['classid']=pdo_getcolumn('jy_edu_lesson',array('id'=>$item['lesson_id']),'classid');
				$item['classtitle']=pdo_getcolumn('jy_edu_class',array('id'=>$item['classid']),'title');
				$item['classworkerid']=pdo_getcolumn('jy_edu_class',array('id'=>$item['classid']),'workerid');
				$item['classgroup']=pdo_getcolumn('jy_edu_class_group',array('id'=>$item['classid']),'title');
				$item['classworker']=pdo_getcolumn('jy_edu_worker',array('id'=>$item['classworkerid']),'name');
				$item['lessontimes']=pdo_getcolumn('jy_edu_lesson',array('id'=>$item['lesson_id']),'times');
			}
			if($item['storeid']){
				$item['storetitle']=pdo_getcolumn('jy_edu_store',array('id'=>$item['storeid']),'title');
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('title'=>'学员_username','type'=>'img_string','img'=>'avatar',
			'data'=>array(
				array('title'=>'家长：','name'=>'nickname'),
				array('title'=>'学员：','name'=>'name','unit'=>'sex')
				)
			),
			array('name'=>'storetitle','title'=>'所属校区','type'=>'string'),
			array('name'=>'classtitle','title'=>'所属班级','type'=>'string'),
			array('name'=>'lessontitle','title'=>'请假课程','type'=>'string'),
			array('name'=>'dayymb','title'=>'请假日期','type'=>'string'),
			array('name'=>'dayhour','title'=>'请假时间','type'=>'string'),
		),'action'=>array(
			array('title'=>'审核操作','type'=>'modal','op'=>'edit'),
		)),
		'search_one'=>array('name'=>'title','add'=>false),
	);
	$return['htmls']=$htmls;
	$return['status']=$this->out_type;
	exi($return);
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_edu_body_out',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'title'=>'审核假条',
		'edit'=>array(
			array('name'=>'status','title'=>'审核操作','type'=>'radio','options'=>'status'),
		)
	);
	$return['htmls']=$htmls;
	$return['status']=$this->out_type;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$id=intval($postdata['id']);
	pdo_update('jy_edu_body_out',array('status'=>intval($postdata['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！','','list');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_edu_body_out',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的假条！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_edu_body_out',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}